#include "LoginWidget.h"
#include "ui_loginwidget.h"

#include "CommonFunc.h"
#include "DataInfo.h"

LoginWidget::LoginWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::LoginWidget)
{
    ui->setupUi(this);
    ui->login_pushButton->setEnableLoading(true);
    QObject::connect(ui->login_pushButton, &LoadingButton::clicked, this, [&]{
        ui->username_lineEdit->setEnabled(false);
        ui->password_lineEdit->setEnabled(false);
    });

    // 登录结果处理
    appendTypeToFunc(XLogin_Result, [&]{
        ui->username_lineEdit->setEnabled(true);
        ui->password_lineEdit->setEnabled(true);
        ui->login_pushButton->stopLoading();
        if (g_httpReplayResult.first != 0) {
            ui->password_lineEdit->setPlaceholderText(g_httpReplayResult.second);
        }

        ui->password_lineEdit->clear();
    });
}

LoginWidget::~LoginWidget()
{
    delete ui;
}

void LoginWidget::on_login_pushButton_clicked()
{
    sendLoginInfo(ui->username_lineEdit->text(), ui->password_lineEdit->text());
}

